package org.kotboot.intercepter;

import org.kotboot.annotations.Auth;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.stereotype.Component;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.lang.invoke.MethodHandle;

///**
// * jisong.sun 2017/9/15 16:22
// */
//@Component
//@Configurable
//public class AuthIntercepterBak extends HandlerInterceptorAdapter {
//    private static Logger LOG  = LoggerFactory.getLogger(AuthIntercepter.class);
//
//    @Override
//    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
//        if(handler instanceof HandlerMethod){
//            Auth methodAnnotation = ((HandlerMethod) handler).getMethodAnnotation(Auth.class);
//            LOG.info("method handler invoke ... ");
//            Auth annotation = handler.getClass().getAnnotation(Auth.class);
//            if(null != annotation){
//                LOG.info("annotation not null , need auth");
//            }else{
//                String servletPath = request.getServletPath();
//                LOG.info(servletPath);
//            }
//        }
////        SecretKey generalKey = JwtKit.generalKey();
////        log.info(generalKey.getAlgorithm());
//////        String authorization = request.getHeader("Authorization");
//////        String create = JwtKit.create(authorization);
//////        log.info("生成的token:{}",create);
////        String stoken = request.getHeader("Authorization");
//////        String token = "eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiJqd3QiLCJpYXQiOjE1MDUyNzIyNTksInN1YiI6IjEyMzEyMzEyMyIsImV4cCI6MTUwNTI3NTg1OX1.x9YdW37bE0Hqg2UmKtw7mAhWHQqXM2LSvrDhPFlYdCM";
////        Jws<Claims> claims = null;
////        try{
////            claims = JwtKit.parse(stoken);
////        }catch (SignatureException e){
////            log.info("stoken解密失败");
////            K.http.toUTF8(response);
////            PrintWriter writer = response.getWriter();
////            writer.print(R.ER("验证失败"));
////            return false;
////        }
////        log.info("解密后的数据：{}",claims);
//        return super.preHandle(request, response, handler);
//    }
//}
